//
//  CamCaptureManager.h
//  CamH
//
//  Created by ghu on 12-7-19.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import "CamUtility.h"
enum
{
    TAKEPHOTO_STATE_IDLE        = 1,
    TAKEPHOTO_STATE_CAPTURING   = 2,
    TAKEPHOTO_STATE_SAVING      = 4
};
typedef NSInteger TakePhoto_State;



@protocol CamCaptureManagerDelegate;

@interface CamCaptureManager : NSObject <AVCaptureVideoDataOutputSampleBufferDelegate>
{
@public
    TakePhoto_State     m_takePhotoState;
    AVCaptureFlashMode  m_pFlashMode;
}

@property (nonatomic, retain) AVCaptureSession          *m_pSession;
@property (nonatomic, assign) AVCaptureVideoOrientation  m_orientation;
// 视频输入
@property (nonatomic, retain) AVCaptureDeviceInput      *m_pVideoInput;
// 两种输出：静态图片输出和动态视屏输出
@property (nonatomic, retain) AVCaptureStillImageOutput *m_pStillImageOutput;
@property (nonatomic, retain) AVCaptureVideoDataOutput  *m_pVideoOutput;

@property (nonatomic, setter=setEnableVideoOutput:) BOOL m_bEnableVideoOutput;

@property (nonatomic, assign) id <CamCaptureManagerDelegate> delegate;


+(CamCaptureManager*) singleton;
-(BOOL)setupSession;

- (AVCaptureDevice *) frontFacingCamera;
- (AVCaptureDevice *) backFacingCamera;
- (void)captureStillImage;

// 获取camera数量
- (NSUInteger) cameraCount;
// 切换前后Camera
- (BOOL) toggleCamere;
- (BOOL) hasTorch;
- (BOOL) hasFlash;
- (void) flashMode:(AVCaptureFlashMode)mode;
- (void) torchMode:(AVCaptureTorchMode)mode;
	

@end




@protocol CamCaptureManagerDelegate <NSObject>
@optional
-(void) captureManager:(CamCaptureManager*)captureManager didFailWithError:(NSError*)error;
-(void) captureManagerDeviceConfigurationChanged:(CamCaptureManager*)captureManager;

// session callback
-(void) captureManager:(CamCaptureManager*)captureManager changeSessionState:(BOOL)bRunning;
// take picture callback
-(void) captureManager:(CamCaptureManager*)captureManager changeStillImageCaptureingState:(BOOL)bCapturing;
-(void) captureManagerStillImageCaptured:(CamCaptureManager*)captureManager didOutputSampleBuffer:(CMSampleBufferRef)buffer withError:(NSError*)error;
//preview callback
-(void) captureManagerPreview:(CamCaptureManager*)captureManager didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer;
-(void) captureManagerRecordingBegin:(CamCaptureManager*)captureManager;
-(void) captureManagerRecordingFinished:(CamCaptureManager*)captureManager;

                        
@end
